package com.example.studyproject.loginInterceptor;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @program: StudyProject
 * @description: aop拦截登录
 * @author: kangwei
 * @create: 2023-03-10 10:38
 **/
//@Aspect
//@Component
@Slf4j
public class LoginAspect {

    /**
     * 切点方法
     */
    @Pointcut("execution(* com.example.studyproject.loginInterceptor..*.*(..))")
    public void pointCut() {
    }

    /**
     * 前置方法
     */
    @Before("pointCut()")
    public void before() {
    }

    /**
     * 环绕⽅法
     */

    @Around("pointCut()")
    public Object doAround(ProceedingJoinPoint joinPoint) {
        Object obj = null;
        log.info("Around ⽅法开始执⾏");
        try {
            // 执⾏拦截⽅法
            obj = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        log.info("Around ⽅法结束执⾏");
        return obj;
    }
}
